refactor(gradio): decompose training interface into focused modules#774
Conversation
📝 WalkthroughWalkthroughThis PR decomposes the monolithic training.py interface into modular, composable tab builders for dataset management, LoRA training, and LoKr training, introducing new i18n strings across four languages (English, Hebrew, Japanese, Chinese) and adding AST-based contract tests to validate the refactored architecture. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 9
🧹 Nitpick comments (2)
acestep/ui/gradio/interfaces/training.py (1)
38-59: Apply resolved epoch defaults to LoKr tab too for debug/default parity.Line [38] computes epoch defaults from
DEBUG_TRAINING, but Line [59] callscreate_training_lokr_tab()without forwarding them, so LoKr epochs remain fixed independently.💡 Suggested direction
training_section.update( create_training_lora_tab( epoch_min=epoch_min, epoch_step=epoch_step, epoch_default=epoch_default, ) ) - training_section.update(create_training_lokr_tab()) + training_section.update( + create_training_lokr_tab( + epoch_min=epoch_min, + epoch_step=epoch_step, + epoch_default=epoch_default, + ) + )Also mirror that signature in:
acestep/ui/gradio/interfaces/training_lokr_tab.pyacestep/ui/gradio/interfaces/training_lokr_tab_run_export.py🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@acestep/ui/gradio/interfaces/training.py` around lines 38 - 59, The epoch defaults resolved by _resolve_epoch_slider_defaults() are not passed to create_training_lokr_tab(), so LoKr uses hardcoded epochs; update the call in create_training_lokr_tab() invocation to forward epoch_min, epoch_step, epoch_default, and then modify the create_training_lokr_tab function signature in both training_lokr_tab.py and training_lokr_tab_run_export.py to accept (epoch_min, epoch_step, epoch_default) and use those values for the LoKr epoch slider (and any defaults/exports) instead of the fixed constants so debug/default parity is maintained.acestep/ui/gradio/interfaces/training_dataset_tab_label_preview.py (1)
10-11: Expand the public function docstring to include the return contract.Please document what keys/components are returned so the facade/wiring contract is self-describing in-code.
As per coding guidelines, "Docstrings are mandatory for all new or modified Python modules, classes, and functions. Docstrings must be concise and include purpose plus key inputs/outputs and raised exceptions when relevant."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@acestep/ui/gradio/interfaces/training_dataset_tab_label_preview.py` around lines 10 - 11, Update the docstring for build_dataset_label_and_preview_controls to include the return contract: list the dict keys returned (e.g., keys for auto-label controls, sample-preview components, any Gradio Blocks/Elements) and describe the type/value for each key and their role in the wiring/facade (for example "auto_label_controls: Gradio Block containing inputs/buttons", "preview_panel: Gradio Component showing sample preview", etc.), and mention any exceptions or error conditions; keep it concise and follow existing module docstring style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@acestep/ui/gradio/i18n/he.json`:
- Around line 447-475: Update the Hebrew locale file to translate the remaining
English LoKr strings: replace values for keys train_section_tensors,
train_section_lora, train_section_params, lokr_section_tensors,
lokr_section_settings, lokr_linear_dim, lokr_linear_dim_info, lokr_linear_alpha,
lokr_linear_alpha_info, lokr_factor, lokr_factor_info, lokr_decompose_both,
lokr_decompose_both_info, lokr_use_tucker, lokr_use_tucker_info,
lokr_use_scalar, lokr_use_scalar_info, lokr_weight_decompose,
lokr_weight_decompose_info, lokr_learning_rate_info, lokr_checkpoint_epoch, and
lokr_checkpoint_epoch_info with appropriate Hebrew translations consistent with
existing style (keep code/backtick examples like `.pt` as-is and preserve
emoji/button text where present).
In `@acestep/ui/gradio/i18n/ja.json`:
- Around line 434-456: Several LoKr locale entries are still in English; update
the specified keys (lokr_linear_dim_info, lokr_linear_alpha_info,
lokr_factor_info, lokr_decompose_both_info, lokr_use_tucker_info,
lokr_use_scalar_info, lokr_weight_decompose_info, lokr_learning_rate_info,
lokr_checkpoint_epoch, lokr_checkpoint_epoch_info) to proper Japanese
translations consistent with surrounding entries (e.g., explain rank/dimension,
scaling factor, Kronecker factor, decomposing both sides, Tucker decomposition,
scalar gating, weight decomposition, learning rate guidance, checkpoint epoch
label and selection guidance) and replace the English strings in the ja.json
file accordingly.
In `@acestep/ui/gradio/i18n/zh.json`:
- Around line 434-456: Several LoKr localization strings in zh.json are still in
English; update the listed keys (lokr_linear_dim_info, lokr_linear_alpha_info,
lokr_factor_info, lokr_decompose_both_info, lokr_use_tucker_info,
lokr_use_scalar_info, lokr_weight_decompose_info, lokr_learning_rate_info,
lokr_checkpoint_epoch, lokr_checkpoint_epoch_info) with proper Chinese
translations consistent with the surrounding entries, preserving meaning (e.g.,
describe rank/dimension, scaling factor, Kronecker factor, decomposing both
sides, Tucker decomposition, scalar gating, weight decomposition, learning rate
guidance, and checkpoint selection) and keep any UI emojis or punctuation style
consistent with other zh.json entries.
In `@acestep/ui/gradio/interfaces/training_dataset_tab_label_preview.py`:
- Around line 70-95: The hardcoded English UI strings in the training dataset
preview need localization: update the Textbox and Dropdown initializers
(edit_caption, edit_genre, prompt_override, edit_lyrics) to use the translation
function t(...) for placeholders, the prompt_override choices/values, and any
labels currently using literals; specifically replace "Music description...",
"pop, electronic, dance...", the Dropdown choices/value ("Use Global Ratio",
"Caption", "Genre"), and the lyrics placeholder "[Verse 1]\nLyrics
here...\n\n[Chorus]\n..." with appropriate t(...) keys (e.g.,
t("training.caption_placeholder"), t("training.genre_placeholder"),
t("training.prompt_override_use_global"), t("training.prompt_override_caption"),
t("training.prompt_override_genre"), t("training.lyrics_placeholder")) so all
strings are localized.
In `@acestep/ui/gradio/interfaces/training_dataset_tab_save_preprocess.py`:
- Around line 64-70: The Dropdown instantiation for preprocess_mode hardcodes
English strings; wrap the label, choices and info text in the translation
function (t) so they render localized UI copy. Update the gr.Dropdown call for
preprocess_mode to use t("...") for label ("Preprocess For"), each choice
("LoRA", "LoKr") via translated strings or a mapped list, and the info string
("LoRA keeps compatibility mode; LoKr uses per-sample source-style context.") so
all displayed text uses t(...) instead of literal English.
In `@acestep/ui/gradio/interfaces/training_dataset_tab_scan_settings.py`:
- Around line 13-40: The UI contains hardcoded English in the quick-start
paragraph and two section headers; replace those literal strings with
translation lookups (use t("training.quick_start_message") for the paragraph and
t("training.load_section_title") and t("training.scan_section_title") for the
headings) inside the existing gr.HTML and gr.HTML("<h4>...") calls (referenced
as the first gr.HTML block and the two gr.HTML header calls) and add
corresponding keys to the locale resource files so all locales render the same
copy.
- Around line 59-95: The Dataframe headers and the LM checkbox label/info are
hardcoded English; update audio_files_table to use translated strings via the
t(...) function for each header (e.g., replace "#", "Filename", "Duration",
"Lyrics", "Labeled", "BPM", "Key", "Caption" with t(...) keys you add like
training.table_index, training.table_filename, etc.) and replace the static
label/info for format_lyrics and transcribe_lyrics with t(...) keys (e.g.,
training.format_lyrics_label, training.format_lyrics_info,
training.transcribe_lyrics_label, training.transcribe_lyrics_info) so all
user-facing text in audio_files_table, format_lyrics, and transcribe_lyrics is
localized.
In `@acestep/ui/gradio/interfaces/training_lora_tab_run_export.py`:
- Around line 91-95: The UI strings for the Textbox named resume_checkpoint_dir
are not localized; update the Textbox initialization so its label and info use
the localization function (e.g., t("...")) instead of hardcoded English text —
replace label="Resume Checkpoint" with label=t("...") and info="Directory of a
saved LoRA checkpoint to resume from" with info=t("...") in the
resume_checkpoint_dir declaration inside training_lora_tab_run_export.py to
ensure locale consistency.
In `@acestep/ui/gradio/interfaces/training.py`:
- Around line 40-47: The HTML header currently hardcodes English inside the
gr.HTML(...) call; replace the static English strings with localized text by
calling the localization function (e.g., t("...")) for both the title and
subtitle and injecting those localized values into the HTML template used in
gr.HTML. Locate the gr.HTML(...) block in training.py and change the embedded
"<h2>🎵 LoRA Training for ACE-Step</h2>" and the <p> subtitle to use t("...")
results (for example t("training.header.title") and
t("training.header.subtitle")) so the rendered UI uses translated text.
---
Nitpick comments:
In `@acestep/ui/gradio/interfaces/training_dataset_tab_label_preview.py`:
- Around line 10-11: Update the docstring for
build_dataset_label_and_preview_controls to include the return contract: list
the dict keys returned (e.g., keys for auto-label controls, sample-preview
components, any Gradio Blocks/Elements) and describe the type/value for each key
and their role in the wiring/facade (for example "auto_label_controls: Gradio
Block containing inputs/buttons", "preview_panel: Gradio Component showing
sample preview", etc.), and mention any exceptions or error conditions; keep it
concise and follow existing module docstring style.
In `@acestep/ui/gradio/interfaces/training.py`:
- Around line 38-59: The epoch defaults resolved by
_resolve_epoch_slider_defaults() are not passed to create_training_lokr_tab(),
so LoKr uses hardcoded epochs; update the call in create_training_lokr_tab()
invocation to forward epoch_min, epoch_step, epoch_default, and then modify the
create_training_lokr_tab function signature in both training_lokr_tab.py and
training_lokr_tab_run_export.py to accept (epoch_min, epoch_step, epoch_default)
and use those values for the LoKr epoch slider (and any defaults/exports)
instead of the fixed constants so debug/default parity is maintained.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9926c490-1752-4a0a-8f77-760692b77326
📒 Files selected for processing (17)
acestep/ui/gradio/i18n/en.jsonacestep/ui/gradio/i18n/he.jsonacestep/ui/gradio/i18n/ja.jsonacestep/ui/gradio/i18n/zh.jsonacestep/ui/gradio/interfaces/training.pyacestep/ui/gradio/interfaces/training_contract_ast_utils.pyacestep/ui/gradio/interfaces/training_dataset_builder_tab.pyacestep/ui/gradio/interfaces/training_dataset_tab_label_preview.pyacestep/ui/gradio/interfaces/training_dataset_tab_save_preprocess.pyacestep/ui/gradio/interfaces/training_dataset_tab_scan_settings.pyacestep/ui/gradio/interfaces/training_decomposition_contract_test.pyacestep/ui/gradio/interfaces/training_lokr_tab.pyacestep/ui/gradio/interfaces/training_lokr_tab_dataset.pyacestep/ui/gradio/interfaces/training_lokr_tab_run_export.pyacestep/ui/gradio/interfaces/training_lora_tab.pyacestep/ui/gradio/interfaces/training_lora_tab_dataset.pyacestep/ui/gradio/interfaces/training_lora_tab_run_export.py
## Summary
This PR decomposes
acestep/ui/gradio/interfaces/training.pyinto focused training interface builders while preserving wiring contracts and UI behavior.It also restores/extends i18n coverage for newly introduced training/LoKr strings across
en/ja/zh/he, with UTF-8-safe handling to avoid mojibake and preserve emoji labels.What Changed
acestep/ui/gradio/interfaces/training.pyas a thin facade/orchestrator.training_contract_ast_utils.pytraining_dataset_builder_tab.pytraining_dataset_tab_scan_settings.pytraining_dataset_tab_label_preview.pytraining_dataset_tab_save_preprocess.pytraining_lora_tab.pytraining_lora_tab_dataset.pytraining_lora_tab_run_export.pytraining_lokr_tab.pytraining_lokr_tab_dataset.pytraining_lokr_tab_run_export.pytraining_decomposition_contract_test.pyacestep/ui/gradio/i18n/en.jsonacestep/ui/gradio/i18n/ja.jsonacestep/ui/gradio/i18n/zh.jsonacestep/ui/gradio/i18n/he.jsonBehavioral Parity
app.titleemoji/title text integrity (🎛️ ... 💡) in all touched locale files.t(...)instead of hardcoded drift.Validation
Executed:
uv run python -m unittest acestep.ui.gradio.interfaces.training_decomposition_contract_testRan 6 tests ... OKuv run python -m unittest acestep.ui.gradio.events.wiring.decomposition_contract_training_testRan 4 tests ... OKen/ja/zh/he)i18n-json-okScope / Out of Scope
In scope:
Out of scope:
Reviewer Focus
training.py.en/ja/zh/heand absence of mojibake in touched strings.CodeRabbit Scope Guard
Please treat findings as in-scope only when introduced by this FD + i18n patch set.
Manual UI Validation
Summary by CodeRabbit
Release Notes
New Features
Refactor